package MallCoreStatistics

import (
	Router2SystemConfig "gitee.com/fotomxq/weeekj_core/v5/router2/system_config"
)

type ArgsGetStatisticsWhere struct {
	//组织ID
	OrgID int64 `db:"org_id" json:"orgID"`
	//用户ID
	UserID int64 `db:"user_id" json:"userID"`
	//会员配置id
	MemberConfigID int64 `db:"member_config_id" json:"memberConfigID"`
	//商品ID
	GoodsID int64 `db:"goods_id" json:"goodsID"`
	//用户会员有效日期
	MemberValidDate string `db:"member_valid_date" json:"memberValidDate"`
}

// GetStatisticsWhere 根据条件获取统计数据
func GetStatisticsWhere(args *ArgsGetStatisticsWhere) (count int, err error) {
	err = Router2SystemConfig.MainDB.Get(&count,
		"SELECT COALESCE(SUM(goods_num), 0)FROM mall_core_statistics WHERE org_id = $1 AND user_id = $2 AND delete_at < to_timestamp(1000000) AND member_config_id = $3  AND goods_id = $4 AND member_valid_date = $5 and is_effective_stats = $6",
		args.OrgID, args.UserID, args.MemberConfigID, args.GoodsID, args.MemberValidDate, 1)
	if err != nil {
		return
	}
	//反馈
	return
}
